local skel = fk.CreateSkill {
  name = "emo__yugui",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__yugui"] = "欲鬼",
  [":emo__yugui"] = "锁定技，其他男性角色进入濒死状态时，你回复一点体力。你进入濒死状态时，每名男性角色随机获得你一张牌。",
}

skel:addEffect(fk.EnterDying, {
  anim_type = "negative",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(skel.name) then
      if target ~= player then
        event:setCostData(self, {anim_type = "defensive"})
        return target:isMale()
      else
        return table.find(player.room.alive_players, function (p)
          return p:isMale() and p ~= player
        end)
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if player ~= target then
      room:recover { num = 1, skillName = skel.name, who = player, recoverBy = player }
    else
      local cards = player:getCardIds("he")
      local targets = table.filter(room:getAlivePlayers(), function (p)
        return p:isMale() and p ~= player
      end)
      if #targets == 0 or #cards == 0 then return end
      targets = table.slice(targets, 1, #cards + 1)
      table.shuffle(cards)
      room:doIndicate(player, targets)
      local moves = {}
      for i = 1, #targets do
        table.insert(moves, {
          ids = {cards[i]},
          from = player,
          to = targets[i],
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonPrey,
          skillName = skel.name,
          proposer = targets[i],
          visible = false,
        })
      end
      room:moveCards(table.unpack(moves))
    end
  end,
})

return skel
